import bisect


class Solution:
    def InversePairs(self, data: List[int]) -> int:
        if not data: return 0

        count = 0
        a = [data[0]]

        for i in range(1, len(data)):
            if data[i] < a[-1]:
                p = bisect.bisect(a, data[i])
                count += len(a) - p
                a[p:p] = [data[i]]  # 切片操作更快
            else:
                a.append(data[i])

        return count % 1000000007